﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Maverick.WebUI.Infrastructure;

namespace Maverick
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                null, // Route name
                "forum/{title}/{parentID}/add", // URL with parameters
                new { controller = "Messages", action = "Add", parentID = "", title = "" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "forum/{title}/{parentID}/{messageID}/edit", // URL with parameters
                new { controller = "Messages", action = "Edit", title = "", parentID = "", messageID = "" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "forum/add", // URL with parameters
                new { controller = "Threads", action = "Add", categoryID = "" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "forum/edit", // URL with parameters
                new { controller = "Threads", action = "Edit" } // Parameter defaults
            );

            routes.MapRoute(
                null, // Route name
                "forum/{title}/{messageID}/edit", // URL with parameters
                new { controller = "Threads", action = "Edit", messageID = "", title = "" } // Parameter defaults
            );

            routes.MapRoute(
                "Thread", // Route name
                "forum/{title}/{parentID}", // URL with parameters
                new { controller = "Messages", action = "List", parentID = "", title = "" } // Parameter defaults
            );

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Threads", action = "List", id = UrlParameter.Optional } // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RegisterRoutes(RouteTable.Routes);
            ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory());
        }
    }
}